//
//  PosApplyStore.m
//  NewPro
//
//  Created by RYX on 2018/11/1.
//  Copyright © 2018年 何荧红. All rights reserved.
//

#import "PosApplyStore.h"
#import "PosChildModel.h"
#import "PosApplyModel.h"

@implementation PosApplyStore

#pragma mark - 获取pos商品列表
- (void)getPosListArrWithTopId:(NSString *)topId Success:(void(^)(NSArray *listArr))success Failure:(void(^)(NSError *error))failure{
    
    NSString *url = [NSString stringWithFormat:@"%@/api/category/model/list/%@",IP,topId];
    
    [HttpTool getUrlWithString:url parameters:nil success:^(id responseObject) {
        
        NSError *error = [HttpTool inspectError:responseObject];
        
        if (error == nil) {
            
            NSArray *arr = [PosChildModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"][@"children"]];
            
            success(arr);
            
        }else{
            
            failure(error);
        }
    } failure:^(NSError *error) {
        
        failure(error);
    }];
}

#pragma mark - 获取pos商品详情
- (void)getPosDetailWithID:(NSString *)uid Success:(void(^)(PosApplyModel *model))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/posModel/getPosModel",IP];
    NSDictionary *prams = @{
                          @"id":uid
                          };
    [HttpTool postUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            PosApplyModel *model = [PosApplyModel  mj_objectWithKeyValues:responseObject[@"data"][@"item"]];
            model.rules = responseObject[@"data"][@"rules"];
            success(model);
        }else{
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

@end
